home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / db / esm-3.1 / esm-3 / usr / local / sm / src / serverlib / redo / redoGetUnique.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-05  |  5.2 KB  |  218 lines

  1. /*
  2.  *   $RCSfile: redoGetUnique.c,v $  
  3.  *   $Revision: 1.1.1.1 $  
  4.  *   $Date: 1996/05/04 21:55:57 $      
  5.  */ 
  6. /**********************************************************************
  7. * EXODUS Database Toolkit Software
  8. * Copyright (c) 1991 Computer Sciences Department, University of
  9. *                    Wisconsin -- Madison
  10. * All Rights Reserved.
  11. *
  12. * Permission to use, copy, modify and distribute this software and its
  13. * documentation is hereby granted, provided that both the copyright
  14. * notice and this permission notice appear in all copies of the
  15. * software, derivative works or modified versions, and any portions
  16. * thereof, and that both notices appear in supporting documentation.
  17. *
  18. * THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY OF WISCONSIN --
  19. * MADISON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.  
  20. * THE DEPARTMENT DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
  21. * WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
  22. *
  23. * The EXODUS Project Group requests users of this software to return 
  24. * any improvements or extensions that they make to:
  25. *
  26. *   EXODUS Project Group 
  27. *     c/o David J. DeWitt and Michael J. Carey
  28. *   Computer Sciences Department
  29. *   University of Wisconsin -- Madison
  30. *   Madison, WI 53706
  31. *
  32. *     or exodus@cs.wisc.edu
  33. *
  34. * In addition, the EXODUS Project Group requests that users grant the 
  35. * Computer Sciences Department rights to redistribute these changes.
  36. **********************************************************************/
  37.  
  38.  
  39. #include "sysdefs.h"
  40. #include "ess.h"
  41. #include "checking.h"
  42. #include "trace.h"
  43. #include "error.h"
  44. #include "list.h"
  45. #include "pool.h"
  46. #include "tid.h"
  47. #include "io.h"
  48. #include "lock.h"
  49. #include "object.h"
  50. #include "msgdefs.h"
  51. #include "thread.h"
  52. #include "latch.h"
  53. #include "semaphore.h"
  54. #include "link.h"
  55. #include "lsn.h"
  56. #include "bf.h"
  57. #include "log.h"
  58. #include "volume.h"
  59. #include "logrecs.h"
  60. #include "trans.h"
  61. #include "bitmap.h"
  62. #include "openlog.h"
  63. #include "io_extfuncs.h"
  64. #include "bf_extfuncs.h"
  65. #include "bm_extfuncs.h"
  66. #include "trans_extfuncs.h"
  67. #include "redo_extfuncs.h"
  68. #include "logaction.h"
  69. #include "util_funcs.h"
  70. #include "thread_globals.h"
  71. #include "log_globals.h"
  72. #include "log_extfuncs.h"
  73.  
  74.  
  75.  void
  76. redoGetUnique (
  77.  
  78.     LOGRECORDHDR        *record 
  79. )
  80. {
  81.  
  82.     register VOLREC        *volRec;
  83.     register PID        *pid;
  84.     register GROUPLINK    *groupLink;
  85.     register UNIQUE        *mapPtr;
  86.     UNIQUE                *unique;
  87.     FOUR                *word;
  88.     PID                    bitmapPid;
  89.     DIRTYPAGEINFO        *dirtyInfo;
  90.     BITMAPPAGE            *bitmapPage;
  91.  
  92.  
  93.     TRPRINT(TR_IO|TR_LOG, TR_LEVEL_1, ("lsn:%d", record->recordLSN.offset));
  94.  
  95.     /*
  96.      *    get a pointer to the name in the record
  97.      */
  98.     pid = &(record->actionPid);
  99.     TRPRINT(TR_IO|TR_LOG, TR_LEVEL_2, ("pid:%d", pid->page));
  100.  
  101.     /*
  102.      *    get a pointer to the name in the record
  103.      */
  104.     word = (FOUR *) GET_LOG_IMAGE(record, 0);
  105.     TRPRINT(TR_IO|TR_LOG, TR_LEVEL_2, ("word:%d", *word));
  106.  
  107.     /*
  108.      *    get a pointer to the name in the record
  109.      */
  110.     unique = (UNIQUE *) GET_LOG_IMAGE(record, 1);
  111.     TRPRINT(TR_IO|TR_LOG, TR_LEVEL_2, ("unique:%d", *unique));
  112.  
  113.     /*
  114.      *    check to see if the page is in the dirty page list
  115.      */
  116.     if ((dirtyInfo = searchDirtyPageTable(pid)) == NULL)    {
  117.  
  118.         /*
  119.          *    don't need to redo
  120.          */
  121.         TRPRINT(TR_RECOVER, TR_LEVEL_2, ("dirty page not present"));
  122.         return;
  123.     }
  124.  
  125.     /*
  126.      *  check to see if the lrc on the page is greater than
  127.      *  the lrc in the log record.
  128.      *  Also check the lsn for the case of pages which never made it
  129.      *  back from the client.
  130.      */
  131.     if (CHECK_PAGE_LRC_LESS_DIRTYINFO(record->actionLRC, record->recordLSN, dirtyInfo)) {
  132.  
  133.         /*
  134.          *  don't need to redo
  135.          */
  136.         TRPRINT(TR_RECOVER, TR_LEVEL_2, ("dirty info page lrc later"));
  137.         return;
  138.     }
  139.  
  140.     if ((volRec = io_FindVolRec(pid->volid)) == NULL)    {
  141.  
  142.         SM_ERROR(TYPE_FATAL, Active->errno);
  143.     }
  144.  
  145.     /*
  146.      *    initialize the pid with the volume
  147.      */
  148.     bitmapPid.volid = volRec->header->volid;
  149.     bitmapPid.page    = pid->page;
  150.  
  151.     /*
  152.      *    read in the page
  153.      */
  154.     if ((groupLink = bf_ReadPage(volRec->bufGroup, &bitmapPid,
  155.                                  BITMAP_PAGE2SIZE, BF_SEM)) == NULL)    {
  156.  
  157.         SM_ERROR(TYPE_FATAL, esmINTERNAL);
  158.     }
  159.  
  160.     /*
  161.      *    get a pointer to the bitmap page
  162.      */
  163.     bitmapPage = (BITMAPPAGE *) groupLink->bufFrame;
  164.  
  165.     /*
  166.      *  check to see if the lrc on the page is greater than
  167.      *  the lrc in the log record
  168.      */
  169.     if (compareLRC( &(record->actionLRC), &(bitmapPage->lrc)) <= 0) {
  170.  
  171.         /*
  172.          *    don't need to redo
  173.          */
  174.         TRPRINT(TR_RECOVER, TR_LEVEL_2, ("actual page lrc later"));
  175.  
  176.         /*
  177.          *    mark the page lrc
  178.          */
  179.         dirtyInfo->lrc = bitmapPage->lrc;
  180.  
  181.         /*
  182.          *    release the page, clean
  183.          */
  184.         signalSemaphore( &(groupLink->pageHash->semaphore) );
  185.         bf_UnfixPage(groupLink, BF_DEFAULT, FALSE);
  186.         return;
  187.     }
  188.  
  189.     /*
  190.      *    get the pointer to the word map
  191.      */
  192.     mapPtr = (UNIQUE *) groupLink->bufFrame;
  193.  
  194.     /*
  195.      *    get the current unique value
  196.      */
  197.     mapPtr[*word] = *unique;
  198.     TRPRINT(TR_IO, TR_LEVEL_2, ("unique:%x", *unique));
  199.  
  200.     /*
  201.      *    mark the lrc
  202.      *    Set up the firstLSN/LRC for the page
  203.      */
  204.     bitmapPage->lrc = record->actionLRC;
  205.     DEPEND_LOG(groupLink->pageHash, 0, &(record->recordLSN), &(record->actionLRC));
  206.     TRPRINT(TR_RECOVER, TR_LEVEL_2, ("marking new page lrc:%d", bitmapPage->lrc.count));
  207.  
  208.     /* 
  209.      *    signal the semaphore
  210.      */
  211.     signalSemaphore( &(groupLink->pageHash->semaphore) );
  212.  
  213.     /*
  214.      *    unfix the page
  215.      */
  216.     bf_UnfixPage(groupLink, BF_DEFAULT, TRUE);
  217. }
  218.